package hot100;

import DTO.TreeNode;

public class sortedArrayToBST2 {
    public TreeNode sortedArrayToBST(int[] nums) {
        return dfs(nums,0,nums.length - 1);
    }

    TreeNode dfs(int[] nums,int l,int r) {
        if(l > r) {
            return null;
        }
        int mid = (l+r) / 2;
        TreeNode root = new TreeNode(nums[mid]);
        root.left = dfs(nums,l,mid - 1);
        root.right = dfs(nums,mid + 1,r);
        return root;
    }
}
